package com.atguigu.service.impl;

import com.atguigu.dao.UserDao;
import com.atguigu.dao.impl.UserDaoImpl;
import com.atguigu.pojo.User;
import com.atguigu.service.UserService;

public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();

    /**
     * 注册用户
     *
     * @param user
     */
    @Override
    public void registUser(User user) {
        int i = userDao.saveUser(user);
        System.out.println(i);
    }

    /**
     * 登录
     *
     * @param user
     * @return 如果登录失败  则返回null  登录成功 是返回有值
     */
    @Override
    public User login(User user) {
        return userDao.queryUserByUsernameAndPassword(user.getUsername(), user.getPassword());
    }

    /**
     * 检查此用户是否存在
     *
     * @param username
     * @return 如果true 则存在不能用   反而能用
     */
    @Override
    public boolean existsUsername(String username) {
        if (userDao.queryUserByUsername(username) != null) {
            return true;
        }
        return false;
    }
}
